package Gestion_article;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.jdbc.JdbcConnectionSource;
import com.j256.ormlite.support.ConnectionSource;
import java.sql.SQLException;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author 10073
 */
public class SpeedyDAO {
    private Dao <Article,Integer> articleDAO;
    private Dao <Categorie,Integer> categorieDAO;
    private Dao <Image,Integer> imageDAO;
    private Dao <Marque,Integer> marqueDAO;
    private Dao <Tva,Integer> tvaDAO;
    private static SpeedyDAO unSpeedyDAO;
    private static String databaseURL;
    private static ConnectionSource connexion;
            
    private SpeedyDAO() throws SQLException {
        databaseURL = "jdbc:mysql://localhost/speedy_commun";
        connexion = new JdbcConnectionSource(databaseURL);
        ((JdbcConnectionSource)connexion).setUsername("root");
        ((JdbcConnectionSource) connexion).setPassword("root");
        articleDAO = DaoManager.createDao(connexion, Article.class);
        categorieDAO = DaoManager.createDao(connexion, Categorie.class);
         imageDAO = DaoManager.createDao(connexion, Image.class);
        marqueDAO = DaoManager.createDao(connexion, Marque.class);
        tvaDAO = DaoManager.createDao(connexion, Tva.class);
    }
    
public static Dao<Article, Integer> getArticleDao() throws SQLException{
if(unSpeedyDAO == null)
unSpeedyDAO = new SpeedyDAO();
return unSpeedyDAO.articleDAO;
}
public static Dao<Categorie, Integer> getCategorieDao() throws SQLException{
if(unSpeedyDAO == null)
unSpeedyDAO = new SpeedyDAO();
return unSpeedyDAO.categorieDAO;
}

public static Dao<Image, Integer> getImageDao() throws SQLException{
if(unSpeedyDAO == null)
unSpeedyDAO = new SpeedyDAO();
return unSpeedyDAO.imageDAO;
}
public static Dao<Marque, Integer> getMarqueDao() throws SQLException{
if(unSpeedyDAO == null)
unSpeedyDAO = new SpeedyDAO();
return unSpeedyDAO.marqueDAO;
}

public static Dao<Tva, Integer> getTvaDao() throws SQLException{
if(unSpeedyDAO == null)
unSpeedyDAO = new SpeedyDAO();
return unSpeedyDAO.tvaDAO;
}
    
  
}
